package com.sino.util;

import java.util.Iterator;
import java.util.List;

import com.sino.model.StaticModel;

public class SelectinoCreate {
	StringBuffer sb = new StringBuffer();

	public SelectinoCreate() {
	}

	// 为联动数组赋值，传入List数据列表，默认数组名为subcat
	public void FillMessageJS(List valueList) {
		Iterator it = valueList.iterator();
		int i = 0;
		StaticModel basicDataForm = null;
		while (it.hasNext()) {
			basicDataForm = (StaticModel) it.next();
			sb.append(" subcat[" + i + "] = new Array('"
					+ basicDataForm.getId() + "','" + basicDataForm.getName()
					+ "');");
			i++;
		}
	}

	/*
	 * 为联动数组伏值，传入List数据列表,数组名称
	 */
	public void FillMessageJS(List valueList, String arrName) {
		sb = new StringBuffer();
		int i = 0;
		Iterator it = valueList.iterator();
		StaticModel basicDataForm = null;
		while (it.hasNext()) {
			basicDataForm = (StaticModel) it.next();
			sb.append(arrName + "[" + i + "] = new Array('"
					+ basicDataForm.getId() + "','" + basicDataForm.getName()
					+ "');");
			i++;
		}
	}

	/*
	 * 为3维 联动数组伏值，传入sql语句，默认数组名为subcat
	 */
	public void FillMessageJS3Tqble(List valueList) {
		int i = 0;
		Iterator it = valueList.iterator();
		StaticModel basicDataForm = null;
		while (it.hasNext()) {
			basicDataForm = (StaticModel) it.next();
			sb.append(" subcat[" + i + "] = new Array('"
					+ basicDataForm.getId() + "','" + basicDataForm.getName()
					+ "','" + basicDataForm.getName() + "');");
			i++;
		}
	}

	/*
	 * 为3维 联动数组伏值，传入sql语句，数组名称 FillMessageJS
	 */
	public void FillMessageJS3Tqble(List valueList, String arrName) {
		int i = 0;
		Iterator it = valueList.iterator();
		StaticModel basicDataForm = null;
		while (it.hasNext()) {
			basicDataForm = (StaticModel) it.next();
			sb.append(arrName + "[" + i + "] = new Array('"
					+ basicDataForm.getId() + "','" + basicDataForm.getName()
					+ "','" + basicDataForm.getName() + "');");
			i++;
		}
	}

	// 返回2维数组字符串，默认数组名为subcat
	public String getSelectListLandong(List valueList) {
		FillMessageJS(valueList);
		return sb.toString();
	}

	// 返回2维数组字符串，数组名arrayName
	public String getSelectListLandong(List valueList, String arrayName) {
		FillMessageJS(valueList, arrayName);
		return sb.toString();
	}

	// 返回3维数组字符串，默认数组名为subcat

	public String getSelectListLandong3Table(List valueList) {
		FillMessageJS3Tqble(valueList);
		return sb.toString();
	}

	// 返回3维数组字符串，数组名arrayName
	public String getSelectListLandong3Table(List valueList, String arrayName) {
		FillMessageJS3Tqble(valueList, arrayName);
		return sb.toString();
	}

	public String getSelectList() {
		return sb.toString();
	}
}
